package com.migu.rbac.service;

import com.migu.rbac.repository.SysUserRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 15:10 2019/4/3
 * @Version 1.0
 **/
@Service
@Transactional
public class SysUserRoleService {

    @Autowired
    private SysUserRoleRepository userRoleRepository;

    //更改用户角色列表
    public int updateUserRole(int userid, int[] roles) {
        if (roles.length == 0) {
            return 0;
        }
        //先删除原有权限
        userRoleRepository.deleteUserRole(userid);
        return userRoleRepository.saveUserRole(userid, roles);
    }

    //查询用户对应角色
    public int[] selectRolesByUserId(int userid) {
        return userRoleRepository.selectRolesByUserId(userid);
    }
}
